<template>
  <div>
    <mainTable
      :title="'关于我们'"
      :table="table"
      :change="'title'"
      :type="'content'"
      @btn="btn"
    />
    <el-pagination
      style="text-align:center; margin:20px"
      background
      layout="prev, pager, next"
      :total="totals"
      :page-size="page._limit"
      :current-page.sync="currentPage"
      @current-change="currentChange"
    />
  </div>
</template>

<script>
import { getPageList, getPageById } from '@/api/we'
export default {
  data() {
    return {
      table: [],
      totals: 0,
      currentPage: 0,
      page: {
        _limit: 3,
        _start: 0
      }
    }
  },
  async created() {
    const data = await getPageList()
    this.table = data.data

    this.total()
    this.PageData()
  },
  methods: {
    // 重新获取总数量
    async total() {
      const { data } = await getPageList()
      // console.log(data)
      this.table = await data
      // console.log(this.table)
      this.totals = this.table.length
    },
    // 刷新回显表格指定数量的数据
    async PageData() {
      const { data } = await getPageList(this.page)
      // console.log(data)
      this.table = data
    },
    async currentChange(sum) {
      // console.log(sum)
      const num = this.page._limit * sum - 1
      this.page._start = num
      this.PageData(this.page)
    },
    async btn(id) {
      const data = await getPageById(id)
      console.log(data)
      // 保存
      const res = JSON.stringify(data.data)
      localStorage.setItem('xiangqing', res)
      this.$router.push({
        name: 'details',
        params: {
          data
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.main{
  width: 300px;
  height: 300px;
  border: 1px solid red;
}
</style>
